﻿using Budget.Data;
using Budget.Data.Mappings;
using NHibernate.Cfg;
using NHibernate.Cfg.MappingSchema;
using NHibernate.Dialect;
using Configuration = NHibernate.Cfg.Configuration;

namespace Budget.Tests.Infrastructure.Database
{
    public class SqlceDbInitializer : DBInitializer
    {
        public SqlceDbInitializer(string connectionKey)
            : base(connectionKey)
        {
        }

        internal override Configuration GetConfiguration()
        {
            var mapper = new DomainMapper();
            HbmMapping generateMappings = mapper.GenerateMappings();
            var cfg = new Configuration();
            cfg.DataBaseIntegration(
                x =>
                    {
                        x.Dialect<MsSqlCeDialect>();
                        x.ConnectionStringName = connectionKey;
                    });
            cfg.SetProperty("show_sql", "true");
            cfg.SetProperty("format_sql", "true");

            cfg.AddDeserializedMapping(generateMappings, string.Empty);

            return cfg;
        }
    }
}